package com.example.design.结构型设计模式.组合模式;

import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

// 菜单组，可以包含其他菜单项和菜单组。用于组合组件
public class MenuGroup implements MenuComponent {
    @Getter
    private final String name;
    private final List<MenuComponent> menuComponents = new ArrayList<>();

    public MenuGroup(String name) {
        this.name = name;
    }

    public void add(MenuComponent menuComponent) {
        menuComponents.add(menuComponent);
    }

    public void remove(MenuComponent menuComponent) {
        menuComponents.remove(menuComponent);
    }

    @Override
    public void print() {
        System.out.println("MenuGroup: " + name);
        for (MenuComponent component : menuComponents) {
            component.print();
        }
    }

}
